import Vue from 'vue'
import Routers from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
import Login from '@/Login'
import Home from '@/views/Home'
import AssetAllocation from '@/views/asset-allocation/AssetAllocation'
import FOFbuild from '@/views/asset-allocation/FOFbuild'
import MacroData from '@/views/asset-allocation/MacroData'
import ResearchReport from '@/views/asset-allocation/ResearchReport'
import Details from '@/views/asset-allocation/Details'
Vue.use(Routers)

const router = new Routers({
    routes: [{
            path: '/',
            name: 'Login',
            component: Login,
            // redirect:"/views/Home",//默认跳转到首页

        },
        {
            path: "/views/Home",
            name: 'Home',
            component: Home,
            meta: {
                requireAuth: true,
                keepAlive: true,
            },
        },

        {
            path: '/views/asset-allocation/Details',
            name: 'Details',
            component: Details,
            meta: {
                requireAuth: true,
                keepAlive: true,
            },
        },

        {
            path: "/views/asset-allocation",
            name: 'Home-All',
            component: Home,
            children: [{
                    path: "AssetAllocation",
                    name: 'AssetAllocation',
                    component: AssetAllocation,
                    meta: {
                        requireAuth: true,
                        keepAlive: true,
                    },
                },
                {
                    path: "FOFbuild",
                    name: 'FOFbuild',
                    component: FOFbuild,
                    meta: {
                        requireAuth: true,
                        keepAlive: true,
                    },
                },
                {
                    path: "ResearchReport",
                    name: 'ResearchReport',
                    component: ResearchReport,
                    meta: {
                        requireAuth: true,
                        keepAlive: false,
                    },
                },
                {
                    path: "MacroData",
                    name: 'MacroData',
                    component: MacroData,
                    meta: {
                        requireAuth: true,
                        keepAlive: false,
                    },
                },

            ]
        },

        {

            path: '/404',
            component: () =>
                import ( /* webpackChunkName: "fail" */ '@/views/exception/404'),
        }
    ]
})


// if (localStorage.getItem('token')) {
//     if (localStorage.getItem('token_flag')) {
//         router.push({ path: '/views/asset-allocation/ResearchReport' })
//     }

// }
// let clientInfo =localStorage.getItem('0001')
// clientInfo.replace(/\'/g,'"' )

if (localStorage.getItem('0001')) {

    if (!sessionStorage.getItem('flag')) {

        router.push({ path: '/views/asset-allocation/ResearchReport' })
    }
}
// debugger
router.beforeEach((to, from, next) => {
    //简单路由拦截
    var token;
    if (sessionStorage.getItem('token')) {
        token = sessionStorage.getItem('token')
    } else if (localStorage.getItem('token')) {
        token = localStorage.getItem('token')
    }
    if (token) {


        // if (localStorage.getItem('token')) {
        //     if (flag == 1) {
        //         console.log(3)
        //         next()
        //     } else {
        //         console.log(4)
        //         next()
        //     }
        //     // next()
        //     // router.push({ path: '/views/asset-allocation/ResearchReport' })
        // } else {
        //     console.log(5)
        //     next()
        // }
        next()
    } else {
        next()
            // router.push({ path: '/' })
    }
    // if (to.meta.requireAuth) {

    //     if (sessionStorage.getItem('token')) {
    //         alert('session')
    //         next();
    //     } else if (localStorage.getItem('token')) {
    //         alert('local')
    //         next();
    //     } else {
    //         alert('拦截了')
    //         router.push({ path: '/' });
    //     }
    // } else {
    //     alert('没有拦截')
    //     next();
    // }

});
export default router